<template>
  <div id="app">
    <div id="nav">
      <button @click="go('/home')">Home</button> |
      <button @click="go({ path: '/about', query: { u: 'uuu' } })">
        About
      </button>
      |
      <button @click="go({ name: 'todo', params: { uid: '123' } })">
        todo
      </button>
      |
      <button @click="go('/slot')">
        slot
      </button>
      |
      <button @click="logout">
        退出
      </button>
    </div>
    <transition name="slide-fade">
      <router-view />
    </transition>
  </div>
</template>

<style>
/* 可以设置不同的进入和离开动画 */
/* 设置持续时间和动画函数 */
.slide-fade-enter-active {
  transition: all 0.3s ease;
}
.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter, .slide-fade-leave-to
/* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(10px);
  opacity: 0;
}

#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>

<script>
import { mapMutations } from "vuex";
export default {
  name: "app",
  methods: {
    ...mapMutations(["setAuth"]),
    go(param) {
      this.$router.push(param);
    },
    logout() {
      this.setAuth("");
      this.$router.push("/login");
    }
  }
};
</script>
